package com.ms.game.lobby;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.ConcurrentHashMap;

import com.xpec.c4.game.time.TimeSys;

/**
 * 遊戲列表白名單
 * @author TW15012
 *
 */
public class GameListWhileGroup 
{
	private ConcurrentHashMap<String,GameListWhileData> group = new ConcurrentHashMap<String,GameListWhileData>();
	
	/**
	 * 讀取白名單群組
	 * @return
	 */
	public ConcurrentHashMap<String, GameListWhileData> getGroup() {
		return group;
	}

	/**
	 * 設定白名單群組
	 * @param group
	 */
	public void setGroup(ConcurrentHashMap<String, GameListWhileData> group) {
		this.group = group;
	}
	
	/**
	 * 玩家是否有白名單
	 * @param playerid
	 * @return
	 */
	public boolean hasWhile(String playerid)
	{
		if(!group.containsKey(playerid))
		{
			return false;
		}
		
		long now = TimeSys.currentTimeMills();
		GameListWhileData data = group.get(playerid);
		if(data.expiredtime!=0 && now > data.expiredtime)
		{
			return false;
		}
		
		return true;
	}
	
	
	/**
	 * 讀取玩家遊戲列表白名單
	 * @param playerid
	 * @return
	 */
	public ArrayList<String> getWhileList(String playerid)
	{
		if(!group.containsKey(playerid))
		{
			return null;
		}
		
		return  group.get(playerid).list;
	}
	
	/**
	 * 此遊戲是否對此玩家角色開啟
	 * @param playerid
	 * @param game
	 * @return
	 */
	public boolean isWGame(String playerid , String game)
	{
		if(!group.containsKey(playerid))
		{
			return false;
		}
		
		GameListWhileData data = group.get(playerid);
		return data.list.contains(game);
	}
	
	/**
	 * 玩家角色遊戲開啟對應icon狀態
	 * @param playerid
	 * @param icon
	 * @return
	 */
	public boolean isWIcon(String playerid ,  String icon)
	{
		if(!group.containsKey(playerid))
		{
			return false;
		}
		
		GameListWhileData data = group.get(playerid);
		return data.iconlist.contains(icon);
	}
	
	
	
	/**
	 * 列表 to 字串
	 * @param list
	 * @return
	 */
	public String listToStr(ArrayList<String> list)
	{
		 String txt = Arrays.toString(list.toArray());
		 txt.replace("[", "");
		 txt.replace("]", "");
		 return txt;
	}
	
	/**
	 * 字串 to 列表 
	 * @param <T>
	 * @param list
	 * @return
	 */
	public ArrayList<String> strToList(String txt)
	{
		if(txt==null || txt.isEmpty())
		{
			return new ArrayList<String>();
		}
		
		
		String [] list = txt.replace(" ", "").split(",");
		for(String tt:list)
		{
			tt.replace(" ", "");
		}
		return new ArrayList<String>(Arrays.asList(list));
	}
	
}
